home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gdevppla.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  4.2 KB  |  134 lines

  1. /* Copyright (C) 1999 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gdevppla.c,v 1.2 2000/09/19 19:00:21 lpd Exp $ */
  20. /* Support for printer devices with planar buffering. */
  21. #include "gdevprn.h"
  22. #include "gdevmpla.h"
  23. #include "gdevppla.h"
  24.  
  25.  
  26. /* Set the buf_procs in a printer device to planar mode. */
  27. int
  28. gdev_prn_set_procs_planar(gx_device *dev)
  29. {
  30.     gx_device_printer * const pdev = (gx_device_printer *)dev;
  31.  
  32.     pdev->printer_procs.buf_procs.create_buf_device =
  33.     gdev_prn_create_buf_planar;
  34.     pdev->printer_procs.buf_procs.size_buf_device =
  35.     gdev_prn_size_buf_planar;
  36.     return 0;
  37. }
  38.  
  39. /* Open a printer device, conditionally setting it to be planar. */
  40. int
  41. gdev_prn_open_planar(gx_device *dev, bool upb)
  42. {
  43.     if (upb)
  44.     gdev_prn_set_procs_planar(dev);
  45.     return gdev_prn_open(dev);
  46. }
  47.  
  48. /* Augment get/put_params to add UsePlanarBuffer. */
  49. int
  50. gdev_prn_get_params_planar(gx_device * pdev, gs_param_list * plist,
  51.                bool *pupb)
  52. {
  53.     int ecode = gdev_prn_get_params(pdev, plist);
  54.  
  55.     if (ecode < 0)
  56.     return ecode;
  57.     return param_write_bool(plist, "UsePlanarBuffer", pupb);
  58. }
  59. int
  60. gdev_prn_put_params_planar(gx_device * pdev, gs_param_list * plist,
  61.                bool *pupb)
  62. {
  63.     bool upb = *pupb;
  64.     int ecode = 0, code;
  65.  
  66.     if (pdev->color_info.num_components > 1)
  67.     ecode = param_read_bool(plist, "UsePlanarBuffer", &upb);
  68.     code = gdev_prn_put_params(pdev, plist);
  69.     if (ecode >= 0)
  70.     ecode = code;
  71.     if (ecode >= 0)
  72.     *pupb = upb;
  73.     return ecode;
  74. }
  75.  
  76. /* Set the buffer device to planar mode. */
  77. private int
  78. gdev_prn_set_planar(gx_device_memory *mdev, const gx_device *tdev)
  79. {
  80.     int num_comp = tdev->color_info.num_components;
  81.     gx_render_plane_t planes[4];
  82.     int depth = tdev->color_info.depth / num_comp;
  83.  
  84.     if (num_comp < 3 || num_comp > 4)
  85.     return_error(gs_error_rangecheck);
  86.     /* Round up the depth per plane to a power of 2. */
  87.     while (depth & (depth - 1))
  88.     --depth, depth = (depth | (depth >> 1)) + 1;
  89.     planes[3].depth = planes[2].depth = planes[1].depth = planes[0].depth =
  90.     depth;
  91.     /* We want the most significant plane to come out first. */
  92.     planes[0].shift = depth * (num_comp - 1);
  93.     planes[1].shift = planes[0].shift - depth;
  94.     planes[2].shift = planes[1].shift - depth;
  95.     planes[3].shift = 0;
  96.     return gdev_mem_set_planar(mdev, num_comp, planes);
  97. }
  98.  
  99. /* Create a planar buffer device. */
  100. int
  101. gdev_prn_create_buf_planar(gx_device **pbdev, gx_device *target,
  102.                const gx_render_plane_t *render_plane,
  103.                gs_memory_t *mem, bool for_band)
  104. {
  105.     int code = gx_default_create_buf_device(pbdev, target, render_plane, mem,
  106.                         for_band);
  107.  
  108.     if (code < 0)
  109.     return code;
  110.     if (gs_device_is_memory(*pbdev) /* == render_plane->index < 0 */) {
  111.     code = gdev_prn_set_planar((gx_device_memory *)*pbdev, *pbdev);
  112.     }
  113.     return code;
  114. }
  115.  
  116. /* Determine the space needed by a planar buffer device. */
  117. int
  118. gdev_prn_size_buf_planar(gx_device_buf_space_t *space, gx_device *target,
  119.              const gx_render_plane_t *render_plane,
  120.              int height, bool for_band)
  121. {
  122.     gx_device_memory mdev;
  123.  
  124.     if (render_plane && render_plane->index >= 0)
  125.     return gx_default_size_buf_device(space, target, render_plane,
  126.                       height, for_band);
  127.     mdev.color_info = target->color_info;
  128.     gdev_prn_set_planar(&mdev, target);
  129.     space->bits = gdev_mem_bits_size(&mdev, target->width, height);
  130.     space->line_ptrs = gdev_mem_line_ptrs_size(&mdev, target->width, height);
  131.     space->raster = bitmap_raster(target->width * mdev.planes[0].depth);
  132.     return 0;
  133. }
  134.